<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GET_ORDERS command Example :: Master-Unlock API</title>
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" />
</head>
<body>
<h1>GET_ORDERS</h1>
<?php
	/* Include the library */
	require ('../library/api.php');
	
	/* Call the API */
	$xml = MasterUnlock::CallAPI('GET_ORDERS');
	if (is_string ($xml)) {
		/* Parse the XML stream */
		$data = MasterUnlock::ParseXML($xml);
		
		if (is_array ($data)) {
			if (isset ($data['ERROR_MESSAGE'])) {
				/* The API has returned an error */
				print ('API error : ' . htmlspecialchars ($data['ERROR_MESSAGE']));
			} else {
				/* Everything works fine */
				print ('<table>');

				/* We will print only these fields */
				$fields = array ('ID', 'DATE', 'IMEI', 'CREDITS', 'SERVICE_ID', 
								'SERVICE_NAME', 'SERVICE_TYPE', 'STATUS', 'DELIVERY', 
								'CODES', 'VERIFIABLE', 'COUNTRY_ID', 'RED_ID', 'MOBILE_ID',
								'MEP', 'PROVIDER', 'SERIAL', 'USER', 'ID_BOX',
								'NICK', 'PASSWORD', 'RM');
				
				print ('<tr>');
				foreach ($fields as $field) {
					print ('<td><b>' . htmlspecialchars ($field) . '</b></td>');
				}
				print ('</tr>');

				foreach ($data['ORDER'] as $order) {
					print ('<tr>');
					foreach ($fields as $field) {
						print ('<td>');
						if (isset ($order[$field])) {
							print (htmlspecialchars($order[$field]));
						} else {
							print ('&nbsp;');
						}
						print ('</td>');
					}
					print ('</tr>');
				}
				
				print ('</table>');
			}
		} else {
			/* Parsing error */
			print ('Could not parse the XML stream');
		}
	} else {
		/* Communication error */
		print ('Could not communicate with the api');
	}
?>
<p><a href="./">Go back</a></p>
</body>
</html>